/***********************************************************************
 * Module:  QuestionImage.java
 * Author:  DAC
 * Purpose: Defines the Class QuestionImage
 ***********************************************************************/
package com.group1.model;
import java.util.*;

import org.hibernate.Query;
import org.hibernate.Session;

/** @pdOid 1c10f60c-8358-4d69-8919-162e79984192 */
public class QuestionImage {
   /** @pdOid efeb66e1-a065-470f-89b8-8ea4820a5f82 */
   protected void finalize() {
      // TODO: implement
   }
   
   /** @pdOid 665dd197-0020-4d4d-a58e-ddc1458ab584 */
   public Integer questimId;
   /** @pdOid fa7804b0-e235-4960-9c99-20cae7f04de1 */
   public java.lang.String questimLink;
   
   /** @pdRoleInfo migr=no name=Question assc=figuresOfQuestions mult=0..1 side=A */
   public Question question;
   /** @pdRoleInfo migr=no name=AnswerItem assc=picturesForAnswerItems mult=0..1 side=A */
   public AnswerItem answerItem;
   
   public static List<QuestionImage> getAllQuestImg(Session session)
   {
	   Query query = session.createQuery("from QuestionImage");                
	   List <QuestionImage> list = query.list();
	   return list;
   }
   
   public static QuestionImage getQuestImgByID(Integer questImgID, Session session)
   {
	   return (QuestionImage) session.load(QuestionImage.class, questImgID);
   }
   
   public static List<QuestionImage> getQuestImgByQuestion(Integer questID, Session session)
   {
	   Query query = session.createQuery("from QuestionImage where QUESTION_ID = '" + questID + "'");                
	   List <QuestionImage> list = query.list();
	   return list;
   }
   
   public static List<QuestionImage> getQuestImgByAnswer(Integer anwserID, Session session)
   {
	   Query query = session.createQuery("from QuestionImage where ANSI_ID = '" + anwserID + "'");                
	   List <QuestionImage> list = query.list();
	   return list;
   }
   
   /** @pdOid a2319999-7429-4022-b72e-19171c995961 */
   public Integer getQuestimId() {
      return questimId;
   }
   
   /** @param newQuestimId
    * @pdOid ed0af15f-6adf-4b00-8195-85b035052cd6 */
   public void setQuestimId(Integer newQuestimId) {
      questimId = newQuestimId;
   }
   
   /** @pdOid f19de1cc-7be1-4230-9f6a-ca5e7df173e9 */
   public java.lang.String getQuestimLink() {
      return questimLink;
   }
   
   /** @param newQuestimLink
    * @pdOid f45737b7-a1e6-423d-970c-616396ba892a */
   public void setQuestimLink(java.lang.String newQuestimLink) {
      questimLink = newQuestimLink;
   }
   
   /** @pdOid 16f99dcb-0f7c-42c0-b7c2-fd4456d7e2e7 */
   public QuestionImage() {
      // TODO: implement
   }
   
   
   /** @pdGenerated default parent getter */
   public Question getQuestion() {
      return question;
   }
   
   /** @pdGenerated default parent setter
     * @param newQuestion */
   public void setQuestion(Question newQuestion) {
      if (this.question == null || !this.question.equals(newQuestion))
      {
         if (this.question != null)
         {
            Question oldQuestion = this.question;
            this.question = null;
            oldQuestion.removeQuestionImage(this);
         }
         if (newQuestion != null)
         {
            this.question = newQuestion;
            this.question.addQuestionImage(this);
         }
      }
   }
   /** @pdGenerated default parent getter */
   public AnswerItem getAnswerItem() {
      return answerItem;
   }
   
   /** @pdGenerated default parent setter
     * @param newAnswerItem */
   public void setAnswerItem(AnswerItem newAnswerItem) {
      if (this.answerItem == null || !this.answerItem.equals(newAnswerItem))
      {
         if (this.answerItem != null)
         {
            AnswerItem oldAnswerItem = this.answerItem;
            this.answerItem = null;
            oldAnswerItem.removeQuestionImage(this);
         }
         if (newAnswerItem != null)
         {
            this.answerItem = newAnswerItem;
            this.answerItem.addQuestionImage(this);
         }
      }
   }

}